package com.ang.listener;

import com.ang.model.CanalModel;
import org.springframework.stereotype.Component;

import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

@CanalTable("canal-test")
@Component
public class CanalHandler implements EntryHandler<CanalModel> {

//    @Autowired
//    private RedisHandler redisHandler;
//    @Autowired
//    private Cache<Long, Item> itemCache;

    @Override
    public void insert(CanalModel item) {
        System.out.println("insert," + item);
        // 写数据到JVM进程缓存
        //itemCache.put(item.getId(), item);
        // 写数据到redis
        //redisHandler.saveItem(item);
    }

    @Override
    public void update(CanalModel before, CanalModel after) {
        System.out.println("update before," + before);
        System.out.println("update after," + after);
        // 写数据到JVM进程缓存
        //itemCache.put(after.getId(), after);
        // 写数据到redis
        //redisHandler.saveItem(after);
    }

    @Override
    public void delete(CanalModel item) {
        System.out.println("delete," + item);
        // 删除数据到JVM进程缓存
        //itemCache.invalidate(item.getId());
        // 删除数据到redis
        //redisHandler.deleteItemById(item.getId());
    }
}
